@extends('admin.layouts.layout')
@section('content')
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox-title">
                <h5>红包管理</h5>
            </div>
            <div class="ibox-content">
                <form class="form-horizontal " action="{{route('redpacket.index')}}" method="get"
                      enctype="multipart/form-data">
                    {!! csrf_field() !!}
                    <table class="table-striped table-bordered table-hover table-condensed">
                        <tr class="b-group">
                            <td class="b-child" colspan="2">
                                <table class="table-striped table-bordered table-hover table-condensed"
                                       style="margin: 0px;">
                                    <tr class="b-group">
                                        <td>
                                            @include('widget.between_datetime',['lblDateTimeName'=>'申请日期','showEndTime'=>true])
                                        </td>
                                        <td>
                                            @include('widget.query_and_refresh')
                                        </td>
                                        <td>
                                            <div class="form-inline">
                                                <label class="control-label">金额</label>
                                                <div class="input-daterange input-group">
                                                    <input autocomplete="off" oninput="value=value.replace(/[^\d]/g,'')"
                                                           type="text" class="input-sm form-control"
                                                           name="money_from"
                                                           value="{{app('request')->input('money_from')}}"/>
                                                    <span class="input-group-addon">到</span>
                                                    <input autocomplete="off" oninput="value=value.replace(/[^\d]/g,'')"
                                                           type="text" class="input-sm form-control"
                                                           name="money_to"
                                                           value="{{app('request')->input('money_to')}}"/>
                                                </div>
                                                @if ($errors->has('money_from'))
                                                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>{{$errors->first('money_from')}}</span>
                                                @endif
                                                @if ($errors->has('money_to'))
                                                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>{{$errors->first('money_to')}}</span>
                                                @endif
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr class="b-group">
                            {{--                            <th width="10%">--}}
                            {{--                            </th>--}}
                            <td class="b-child" colspan="2">
                                <table class="table-striped table-bordered table-hover table-condensed"
                                       style="margin: 0px;">
                                    <tr class="b-group">
                                        <td class="form-inline">
                                            <label class="control-label">NO</label>
                                            <div class="input-daterange input-group">
                                                <input autocomplete="off" type="text" class="input-sm form-control"
                                                       name="no"
                                                       value="{{app('request')->input('no')}}" placeholder="请输入NO"/>
                                            </div>
                                            @if ($errors->has('no'))
                                                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>{{$errors->first('no')}}</span>
                                            @endif
                                        </td>
                                        <td class="form-inline">
                                            <label class="control-label">账号</label>
                                            <div class="input-daterange input-group">
                                                <input autocomplete="off" type="text" class="input-sm form-control"
                                                       name="account"
                                                       value="{{app('request')->input('account')}}"
                                                       placeholder="请输入账号"/>
                                            </div>
                                            @if ($errors->has('account'))
                                                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>{{$errors->first('account')}}</span>
                                            @endif
                                        </td>
                                        <td class="form-inline">
                                            <label class="control-label">姓名</label>
                                            <div class="input-daterange input-group">
                                                <input autocomplete="off" type="text" class="input-sm form-control"
                                                       name="account_name"
                                                       value="{{app('request')->input('account_name')}}"
                                                       placeholder="请输入姓名"/>
                                            </div>
                                            @if ($errors->has('nickname'))
                                                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>{{$errors->first('account_name')}}</span>
                                            @endif
                                        </td>
                                        <td class="form-inline">
                                            <label class="control-label">状态</label>
                                            <select class="form-control" name="stat" style="width: auto;">
                                                <?php
                                                use \App\Models\Enum\RedPacket;

                                                $stats = RedPacket::getAllStat();
                                                $html = '';
                                                $selected = '';
                                                foreach ($stats as $key => $value) {
                                                    $selected = (app('request')->input('stat') == $key) ? 'selected="selected"' : '';
                                                    $html .= '<option ' . $selected . ' value="' . $key . '">' . $value . '</option>';
                                                }
                                                echo $html;
                                                ?>
                                            </select>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                    <input type="hidden" name="page_size" value="{{$reqPageSize}}"/>
                    <input type="hidden" name="order_by" value="{{$reqOrderBy}}"/>
                    <input type="hidden" name="order_direction" value="{{$reqOrderDirection}}"/>
                </form>
                <table class="table table-striped table-bordered table-hover m-t-md tblData">
                    <thead>
                    <tr id="trOrder">
                        <th class="text-center"><a data-column="id">ID</a></th>
                        <th class="text-center"><a data-column="no">NO</a></th>
                        <th class="text-center"><a data-column="account">收款账号</a></th>
                        <th class="text-center"><a data-column="account_name">真实姓名</a></th>
                        <th class="text-center"><a data-column="money">金额(元)</a></th>
                        <th class="text-center"><a data-column="created_at">申请时间</a></th>
                        <th class="text-center">处理时间</th>
                        <th class="text-center"><a data-column="stat">状态</a></th>
                        <th class="text-center" style="min-width: 13rem">操作</th>
                        <th class="text-center"><a data-column="channel_id">渠道</a></th>
                        <th class="text-center"><a data-column="server_id">服务器</a></th>
                        <th class="text-center"><a data-column="uid">游戏uid</a></th>
                        <th class="text-center"><a data-column="account">游戏账号</a></th>
                        <th class="text-center"><a data-column="nickname">游戏昵称</a></th>
                    </tr>
                    </thead>
                    <tbody class="text-center">
                    <?php
                    $html = '';
                    foreach ($data as $key => $value) {
                        $statTime = $value['stat_' . $value['stat'] . '_time'];

                        //状态
                        $css = 'label-warning';
                        switch ($value['stat']) {
                            case RedPacket::PENDING_PAYMENT:
                                $css = 'label-info';
                                break;
                            case RedPacket::PAYMENT:
                            case RedPacket::REJECTED:
                                $css = '';
                                break;
                            case RedPacket::PAYMENT_FAILED:
                                $css = 'label-danger';
                                break;
                        }
                        $statName = RedPacket::getStatName($value['stat']);

                        $spanStat = "<span class=\"label {$css}\">{$statName}</span>";
                        $spanStat = "<a href=\"javascript:;\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"{$value['error_msg']}\">{$spanStat}</a>";

                        //操作
                        $btnHtml = '';
                        $agreeHtml = '<button class="btn btn-warning btn-xs" style="float:left;" type="button" onclick="window.location.href=\'' . route('redpacket.withdraw', ['id' => $value['id']]) . '\';"><i class="fa fa-check"></i>&nbsp;同意</button>';
                        $rejectHtml = '&nbsp;<button class="btn btn-danger btn-xs" style="float:right;" type="button" onclick="window.location.href=\'' . route('redpacket.reject', ['id' => $value['id']]) . '\';"><i class="fa fa-check"></i>&nbsp;拒绝</button>';
                        $processedHtml = "<span class=\"label label-success\">已处理</span>";
                        switch ($value['stat']) {
                            case RedPacket::PENDING_PAYMENT:
                                $btnHtml = $agreeHtml . $rejectHtml;
                                break;
                            case RedPacket::PAYMENT_FAILED:
                            case RedPacket::PAYMENT:
                            case RedPacket::REJECTED:
                                $btnHtml = $processedHtml;
                                break;
                        }

                        $html .= <<<EOF
                        <tr>
                            <td>{$value['id']}</td>
                            <td>{$value['no']}</td>

                            <td>{$value['to_account']}</td>
                            <td>{$value['real_name']}</td>
                            <td>{$value['money']}</td>
                            <td>{$value['created_at']}</td>
                            <td>{$statTime}</td>
                            <td>{$spanStat}</td>
                            <td style="max-width: 10rem">{$btnHtml}</td>
                            <td>{$value['channel_name']}</td>
                            <td>{$value['server_name']}</td>

                            <td>{$value['uid']}</td>
                            <td>{$value['account']}</td>
                            <td>{$value['nickname']}</td>
                        </tr>
EOF;
                    }
                    echo $html;
                    ?>
                    </tbody>
                </table>
                <div class="pull-left pagination m-t-no">
                    @include('widget.page',['reqPageSize'=>$reqPageSize])
                </div>
                <div class="pull-right pagination m-t-no">
                    <div class="text-center">
                        <?php
                        if (count($data) > 0) {
                            echo $data->appends([
                                'start_time' => $reqStartTime,
                                'end_time' => $reqEndTime,
                                'money_from' => app('request')->input('money_from'),
                                'money_to' => app('request')->input('money_to'),
                                'stat' => app('request')->input('stat'),
                                'account' => app('request')->input('account'),
                                'account_name' => app('request')->input('account_name'),
                                'no' => app('request')->input('no'),
                                'page_size' => app('request')->input('page_size'),
                                'order_by' => app('request')->input('order_by'),
                                'order_direction' => app('request')->input('order_direction'),
                            ])->links();
                        }
                        ?>
                    </div>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>
    </div>
    <script>
    </script>
    <link href="{{loadEdition('/admin/css/plugins/datapicker/bootstrap-datepicker.css')}}" rel="stylesheet">
@endsection
@section('js')
    <script src="{{loadEdition('/admin/js/plugins/datapicker/bootstrap-datepicker.js')}}"></script>
    <script src="{{loadEdition('/admin/js/plugins/datapicker/bootstrap-datepicker.zh-CN.js')}}"></script>
    <script src="{{loadEdition('/js/global.js')}}"></script>
    <script>
        function resetForm() {
            window.location.href = '{{URL::full()}}';
        }
    </script>
@stop